package com.xr.system.student.controller;

import com.xr.core.system.common.annotation.OperationLogAnno;
import com.xr.core.system.common.enums.OperationType;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import com.xr.common.axios.AxiosResult;
import com.xr.common.axios.AxiosEnum;
import com.xr.system.model.student.dto.StudentDto;
import com.xr.system.student.service.IStudentService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * Student信息表
 *
 * @author fzh
 * @email e_341877120_mail@163.com
 * @date 2022-09-29 11:13:09
 */
@RestController
@RequestMapping("/api/v1/student")
public class StudentController {

    @Autowired
    private IStudentService iStudentService;

    /**
     * 根据条件查询列表
     *
     * @param studentDto
     * @return
     */
    @ApiOperation(tags = "查询", value = "查询Student信息")
    @GetMapping("/selectList")
    public AxiosResult selectList(StudentDto studentDto) {
        return iStudentService.selectList(studentDto);
    }

    /**
     * 根据条件分页查询
     *
     * @param currentPage
     * @param pageSize
     * @param studentDto
     * @return
     */
    @OperationLogAnno(module = "Student模块", type = OperationType.SELECT, desc = "分页查询Student信息")
    @GetMapping("/selectPage/{currentPage}/{pageSize}")
    public AxiosResult selectPage(@PathVariable int currentPage, @PathVariable int pageSize, StudentDto studentDto) {
        return iStudentService.selectPage(currentPage, pageSize, studentDto);
    }

    /**
     * 根据id查询单个
     *
     * @param id
     * @return
     */
    @GetMapping("/selectOneById/{id}")
    public AxiosResult selectOneById(@PathVariable Long id) {
        return iStudentService.selectOneById(id);
    }

    /**
     * 新增
     *
     * @param studentDto
     * @return
     */
    @OperationLogAnno(module = "Student模块", type = OperationType.INSERT, desc = "新增Student信息")
    @PostMapping("/insert")
    public AxiosResult insert(@RequestBody StudentDto studentDto) {
        return iStudentService.insert(studentDto);
    }

    /**
     * 更新
     *
     * @param studentDto
     * @return
     */
    @OperationLogAnno(module = "Student模块", type = OperationType.UPDATE, desc = "更新Student信息")
    @PutMapping("/update")
    public AxiosResult update(@RequestBody StudentDto studentDto) {
        return iStudentService.update(studentDto);
    }

    /**
     * 根据id删除单个
     *
     * @param id
     * @return
     */
    @OperationLogAnno(module = "Student模块", type = OperationType.DELETE, desc = "删除Student信息")
    @DeleteMapping("/delete/{id}")
    public AxiosResult delete(@PathVariable Long id) {
        return iStudentService.delete(id);
    }

    /**
     * 根据id集合批量删除
     *
     * @param idList
     * @return
     */
    @OperationLogAnno(module = "Student模块", type = OperationType.DELETE, desc = "批量删除Student信息")
    @PostMapping("/deleteBatch")
    public AxiosResult deleteBatch(@RequestBody List<Long> idList) {
        return iStudentService.deleteBatch(idList);
    }

    /**
     * 导入文件
     *
     * @param file
     * @return
     */
    @OperationLogAnno(module = "Student模块", type = OperationType.IMPORT, desc = "导入Student信息")
    @PostMapping("/importFile")
    public AxiosResult importFile(MultipartFile file) {
        return iStudentService.importFile(file);
    }

    /**
     * 导出文件
     *
     * @param response
     */
    @OperationLogAnno(module = "Student模块", type = OperationType.EXPORT, desc = "导出Student信息")
    @GetMapping("/exportFile")
    public AxiosResult exportFile(HttpServletResponse response) {
        iStudentService.exportFile(response);
        return AxiosResult.success(AxiosEnum.EXPORT_SUCCESS);
    }

}
